﻿using System;
using System.Data;
using System.Windows;
using System.Windows.Media.Imaging;
using CAION2.Models;

namespace CAION2.Classes
{
    public class ManaStone
    {
        public enum ManaStoneType
        {
            None,
            Normal,
            Bonus,
            Special
        }

        private string _translate;
        private DataRow _row;
        private BitmapSource _icon;
        private Visibility _visible;
        private ManaStoneType _slotType;
        private byte _index;
        
        #region Properties
        
        public DataRow Row
        {
            get { return _row; }
            set
            {
                if (Equals(_row, value)) return;
                _row = value;
            }
        }

        public BitmapSource Icon
        {
            get { return _icon; }
            set
            {
                if (Equals(_icon, value)) return;

                _icon = value;
            }
        }

        public Visibility Visible
        {
            get { return _visible; }
            set
            {
                if (Equals(_visible, value)) return;
                _visible = value;
            }
        }

        public string Translate
        {
            get { return _translate; }
            set
            {
                if (Equals(_translate, value)) return;
                _translate = value;
            }
        }

        public ManaStoneType SlotType
        {
            get { return _slotType; }
            set
            {
                Visible = value == ManaStoneType.None ? Visibility.Collapsed : Visibility.Visible;

                if (Equals(_slotType, value)) return;
                _slotType = value;
            }
        }

        public byte Index
        {
            get { return _index; }
            set
            {
                if (Equals(_index, value)) return;
                _index = value;
            }
        }

        #endregion

        private ManaStone()
        {
            Icon = new BitmapImage();
            SlotType = ManaStoneType.None;
        }

        public ManaStone(ManaStoneType slotType, byte index)
        {
            Row = null;
            Icon = new BitmapImage();
            SlotType = slotType;
            Index = index;

            switch (SlotType)
            {
                case ManaStoneType.Bonus:
                    _icon = new BitmapImage(new Uri("pack://application:,,,/CAION2;component/UI2/IconBonusMatter.png", UriKind.Absolute));
                    break;
                case ManaStoneType.Special:
                    _icon = new BitmapImage(new Uri("pack://application:,,,/CAION2;component/UI2/IconSpecialMatter.png", UriKind.Absolute));
                    break;
            }
        }
        
        public ManaStone(DataRow row, ManaStoneType slotType = ManaStoneType.Normal)
        {
            Row = row;
            Icon =
                new BitmapImage(new Uri(DataModel.IconsDirectory + _row["icon_name"] + ".png",
                                        UriKind.RelativeOrAbsolute));
            
            Translate = _row["translate" + DataModel.EngFix].ToString();

            switch (DataModel.EngFix)
            {
                case "":
                    Translate = Translate.Replace("Маг. камень: ", "");
                    Translate = Translate.Replace("Древний маг. камень: ", "");
                    break;
                default:
                    Translate = Translate.Replace("Manastone: ", "");
                    Translate = Translate.Replace("Ancient Manastone: ", "");
                    break;
            }
            Translate = Translate.Replace("/", "\n");

            SlotType = slotType;
        }
        
        public ManaStone Clone()
        {
            return new ManaStone {Row = Row, Icon = Icon, Visible = Visible, Translate = Translate, SlotType = SlotType, Index = Index};
        }

        public ManaStone CloneLite(ManaStoneType slotType, byte index)
        {
            return new ManaStone { Row = Row, Icon = Icon, Visible = Visible, Translate = Translate, SlotType = slotType, Index = index};
        }
    }
}
